package JitTest;

import commander.CLI;
import gitobject.Commit;
//import org.junit.Test;

public class test_Total {
    @org.junit.Test;
    public void test() throws Exception {
        // 初始化仓库
        System.out.println("\n================== jit init repo ==================");
        String[] sInit1 = {"jit","init","C:\\Users\\Alphamxy\\Desktop\\test"};
        CLI.main(sInit1);

        // 测试jit add 和 jit hash 和 jit commit
        // jit add= jit hash + update index
        // add 3个txt，执行后在objects生成对应的对象，创建index，update三个文件的add记录
        // 执行后自动输出add成功和commit成功的信息
        System.out.println("\n================== jit add 1.txt 2.txt==================");
        CLI.main(new String[]{"jit","add","deep"});
        CLI.main(new String[]{"jit","commit","commit 1.txt"});
        CLI.main(new String[]{"jit","add","2.txt"});
        CLI.main(new String[]{"jit","commit","commit 2.txt"});
        // 获取此时的commit,当做一会儿回退的目标commit版本
        String resetTargetCommit = Commit.getLastCommit();

        // 继续add 3.txt，目前index里有1.txt 2.txt 3.txt的add记录
        CLI.main(new String[]{"jit","add","3.txt"});

        // 测试jit remove：
        // 执行后，在index里就删除3.txt的记录，可查看暂存区
        System.out.println("\n================== jit remove 3.txt ==================");
        String[] sInit3 = {"jit","remove","3.txt"};
        CLI.main(sInit3);

        // 再重新把3.txt给add+commit一下，让index区里保存这3个文件的记录
        System.out.println("\n================== jit add & commit 3.txt ==================");
        CLI.main(new String[]{"jit","add","3.txt"});
        CLI.main(new String[]{"jit","commit","commit 3.txt"});

        // 测试jit log
        // 目前3个txt文件都进行add+commit，因此可以log出3个commit记录
        System.out.println("\n================== jit log ==================");
        String[] sInit5 = {"jit","log"};
        CLI.main(sInit5);

        // reset的三种，仅测试jit reset --hard：
        // 执行后工作区和暂存区都回退到第一次add+commit的版本（仅add&commit1.txt 2.txt的时候）
        // 执行成功后，自动打印工作区目录和暂存区目录，可以看到3.txt在工作区和暂存区都被删除了
        System.out.println("\n================== jit reset --hard resetTargetCommit ==================");
        String[] sInit12 = {"jit","reset","--hard", resetTargetCommit};
        CLI.main(sInit12);

        // 最后log一下,删除3.txt后，log的commit记录仅剩2条
        System.out.println("\n================== jit log ==================");
        CLI.main(sInit5);

        // 接下来测试branch
        // 测试jit branch：
        // 执行后直接创建分支testBranch_1
        System.out.println("\n================== jit branch testBranch_1 ==================");
        String[] sInit7 = {"jit","branch","testBranch_1"};
        CLI.main(sInit7);

        // 测试jit branch -b：
        // jit branch -b = jit branch + jit checkout
        // 执行后创建testBranch_2，且指向testBranch_2分支上
        System.out.println("\n================== jit branch -b testBranch_2 ==================");
        String[] sInit6 = {"jit","branch","-b","testBranch_2"};
        CLI.main(sInit6);

        // 打印分支查看结果
        // 当前是在testBranch_2分支上
        System.out.println("\n================== print branches ==================");
        String[] sInit9 = {"jit","branch","-a"};
        CLI.main(sInit9);

        // 再jit checkout 回到master分支
        System.out.println("\n================== jit checkout master ==================");
        String[] sInit8 = {"jit","checkout","master"};
        CLI.main(sInit8);

        // 再查看结果，回到了master分支上
        System.out.println("\n================== print branches ==================");
        CLI.main(sInit9);

    }
}